package com.ruoyi.campus.controller;

import com.ruoyi.campus.domain.Distribution;
import com.ruoyi.campus.domain.vo.DistributionVO;
import com.ruoyi.campus.service.IDistributionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 校区分销商品审核Controller
 * 
 * @author ruoyi
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/campus/distribution")
public class DistributionController extends BaseController
{
    @Autowired
    private IDistributionService distributionService;


    /**
     * 查询校区分销商品审核列表
     */
    @PreAuthorize("@ss.hasPermi('campus:distribution:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributionVO distributionvo)
    {
        startPage();
        List<DistributionVO> list = distributionService.selectDistributionList(distributionvo);
        System.out.println(list);
        return getDataTable(list);
    }

    // /**
    //  * 查询校区分销商品审核列表
    //  */
    // @PreAuthorize("@ss.hasPermi('campus:distribution:list')")
    // @GetMapping("/list")
    // public TableDataInfo list(Distribution distribution)
    // {
    //     startPage();
    //     List<Distribution> list = distributionService.selectDistributionList(distribution);
    //     return getDataTable(list);
    // }

    /**
     * 导出校区分销商品审核列表
     */
    @PreAuthorize("@ss.hasPermi('campus:distribution:export')")
    @Log(title = "校区分销商品审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributionVO distributionvo)
    {
        List<DistributionVO> list = distributionService.selectDistributionList(distributionvo);
        ExcelUtil<DistributionVO> util = new ExcelUtil<DistributionVO>(DistributionVO.class);
        util.exportExcel(response, list, "校区分销商品审核数据");
    }

    /**
     * 获取校区分销商品审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:distribution:query')")
    @GetMapping(value = "/{distriId}")
    public AjaxResult getInfo(@PathVariable("distriId") Integer distriId)
    {
        return success(distributionService.selectDistributionByDistriId(distriId));
    }

    /**
     * 新增校区分销商品审核
     */
    @PreAuthorize("@ss.hasPermi('campus:distribution:add')")
    @Log(title = "校区分销商品审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Distribution distribution)
    {
        return toAjax(distributionService.insertDistribution(distribution));
    }

    /**
     * 修改校区分销商品审核
     */
    @PreAuthorize("@ss.hasPermi('campus:distribution:edit')")
    @Log(title = "校区分销商品审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Distribution distribution)
    {
        return toAjax(distributionService.updateDistribution(distribution));
    }

    /**
     * 删除校区分销商品审核
     */
    @PreAuthorize("@ss.hasPermi('campus:distribution:remove')")
    @Log(title = "校区分销商品审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{distriIds}")
    public AjaxResult remove(@PathVariable Integer[] distriIds)
    {
        return toAjax(distributionService.deleteDistributionByDistriIds(distriIds));
    }
}
